/*
 * @Author: xiaoyan
 * @Date: 2021-11-25 17:54:30
 * @LastEditors: xiaoyan
 * @LastEditTime: 2022-01-28 17:07:52
 * @Description: 
 * @FilePath: \user_auth_front\src\pages\application\components\expandedRow.tsx
 */
import { applicationDel } from '@/api';
import { IApplication } from '@/interface';
import { openModal } from '@/store/modules/app';
import {EditOutlined,DeleteOutlined} from '@ant-design/icons';
import { Button,message,Popconfirm,Table, Tooltip } from "antd";
import { useDispatch } from 'redux-react-hook';
//import dataList from "@/mocks/application"
export default (prop:any)=>{
    const {dataList,modalConf,ajaxList} =prop;
    const columns = [
        {
            title:"应用ID",
            dataIndex:"applicationId",
            key:"applicationId",
        },
        {
            title:"应用名称",
            dataIndex:"name",
            key:"name",
        },
        {
            title:"应用编码",
            dataIndex:"code",
            key:"code",
        },
        {
            title:"应用URL",
            dataIndex:"url",
            key:"url",
        },
        {
            title:"创建时间",
            dataIndex:"createTime",
            key:"createTime",
        },
        {
            title:"操作",
            key:"action",
            width:100,
            render:(val:string,row:IApplication,index:number)=>(
                <>
                    <Tooltip placement="top" title="编辑">
                        <Button type="text" icon={<EditOutlined />} onClick={()=>handleEdit(row.applicationId)}></Button>
                    </Tooltip>
                    <Popconfirm title="确定要删除该应用吗？" okText="确定" cancelText="取消" onConfirm={()=>handleDel(row.applicationId)}>
                        <Tooltip placement="top" title="删除">
                            <Button type="text" icon={<DeleteOutlined />}></Button>
                        </Tooltip>
                    </Popconfirm>
                </>
            ),

        },
    ];

    const dispatch = useDispatch();

    //编辑
    const handleEdit = (id:number)=>{
        Object.assign(modalConf,{title:"编辑机构",data:id});
        const action = openModal(modalConf);
        dispatch(action);
    };
    //单个删除
    const handleDel = (id:number)=>{
        applicationDel({id}).then((res:any)=>{
            if(res.code === 0){
                message.success("删除成功");
                ajaxList({page:1});
            }else{
                message.error(res.msg);
            }
        });
    };

    const rowSelection = {

    };

    return <Table rowKey="applicationId" rowSelection={rowSelection} columns={columns}  dataSource={dataList} pagination={false} />;
}